<?php

	class LoginController extends Controller{

		public function Index(){

			if (!isset($_SESSION['aid']) && !isset($_SESSION['aname'])) {


				if (IS_POST) {

					//先判断验证码
				if(Q('post.code','','strtoupper')!= session('code')){

					$this->error('验证码错误');
				}

				//连接数据库并赋值
				$model = K('Shop_admin');

				//查询数据
				$userInfo = $model->validate_login(Q('post.adminname'),Q('post.adminpwd'));

				if (!$userInfo) {
					
					$this->error($model->error);
				}

				$_SESSION['aid'] = $userInfo['aid'];
				$_SESSION['aname'] = $userInfo['adminname'];

				$this->success('登陆成功',U('Index/index'));

				}

			}else{
				go(U('Index/index'));
			}



			$this->display();
			// p($_POST);die;
		}

		//验证码方法
		public function Code(){

			$obj = new Code();
			$obj->show();
		}

		public function out(){

			session(NULL);

			$this->success('退出成功',U('Admin/Login/index'));


		}


	}





?>